<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Admin;
use think\Route;
use think\Session;

class LoginController extends Controller
{
    public function _initialize()
    {
        parent::_initialize();
        $Model = new Admin;
        $this->Model = $Model;
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return view('user/login');
    }

    public function doLogin(Request $request)
    {
        $res = $this->Model->checkLogin($request);
        
        if(is_string($res)){
            return $this->error($res);
        }else{
            session::set('admin_user',$res['username']);
           $this->success('登录成功正在为您跳转～',url('admin/Index/index'));
        }
    }

    public function loginout()
    {
        session::clear();
        $this->redirect('admin/logincontroller/index');
    }
}